package br.com.onbrain.observe;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import br.com.onbrain.bancodedados.UsuariosDAO;

public class Splash extends Activity implements Runnable{
	 private UsuariosDAO usuarioDAO = new UsuariosDAO(this);
	
	 @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash);
		
		float scale = getResources().getDisplayMetrics().density;
		int value = (int) (1 * scale + 0.5f);
		Log.i("Script", ""+value);
		
		 ImageView iv = (ImageView) findViewById(R.id.splash_ivLogo);
		 
		  Handler handler = new Handler();
	      handler.postDelayed(this, 4000);
	      
	      ObjectAnimator anim = ObjectAnimator.ofFloat(iv, "alpha", 0f,1f);
	      anim.setDuration(3000);
		  
		  iv.setVisibility(View.VISIBLE);
		  anim.start();
		  
			 	   	
	}

	@Override
	public void run() {
		if(usuarioDAO.verificaBancoVazio()==0){
			startActivity(new Intent(this, TelaNoUser.class));
		}
		else{
		 startActivity(new Intent(this, Login.class));
		}
	     finish();
	}

}
